package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCashWithdrawal;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppRoom;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 房间
 */
@Repository
public class AfterRoomDao extends BaseDao<AppRoom> {

    /**
     * 详情
     */
    public AppRoom get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room where id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoom.class);
    }

    /**
     * 详情
     */
    public AppRoom getRoomcode(Integer roomcode){
        if (roomcode==null || roomcode<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room where roomcode = ? ");
        paramList.add(roomcode);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoom.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppRoom appRoom) {
        if (appRoom!=null && appRoom.getId() != null && appRoom.getId() > 0) {
            this.update(appRoom);
        } else {
            appRoom.setId(this.add(appRoom));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_room where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 综合查询
     * @param map
     * @param bean
     */
    public List<AppRoom> findList(Map<String, Object> map, SplitPageBean bean) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM app_room a where 1=1 ");
        if (StringEx.isNotNull(map.get("nick"))) {
            sbStr.append(" and a.nick like ? ");
            paramList.add("%" + map.get("nick") + "%");
        }if (StringEx.isNotNull(map.get("roomname"))) {
            sbStr.append(" and a.roomname like ? ");
            paramList.add("%" + map.get("roomname") + "%");
        }if (StringEx.isNotNull(map.get("phone"))) {
            sbStr.append(" and a.phone = ? ");
            paramList.add(map.get("phone"));
        }if (StringEx.isNotNull(map.get("roomcode"))) {
            sbStr.append(" and a.roomcode = ? ");
            paramList.add(map.get("roomcode"));
        }
        if(StringEx.isNotNull(map.get("status"))){
            sbStr.append(" and a.status = ? ");
            paramList.add(map.get("status"));
        }
        if (!StringEx.isNull(map.get("startDate"))) {
            sbStr.append(" and a.createtime>=? ");
            paramList.add(map.get("startDate"));
        }
        if (!StringEx.isNull(map.get("endDate"))) {
            sbStr.append(" and a.createtime<=? ");
            paramList.add(map.get("endDate"));
        }
        sbStr.append(" order by a.createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppRoom.class, bean);
    }

    /**
     * 根据房间CODE查询房间
     * @param roomcode
     * @param splitPage
     * @return
     */
    public List<AppRoom> selectRoomByCode(String roomcode, SplitPageBean splitPage) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append("select * from app_room where 1=1");
        if (!StringUtils.isEmpty(roomcode)) {
            sbStr.append(" AND roomcode=?");
            paramList.add(roomcode);
        }
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppRoom.class,splitPage);
    }

}
